package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DishMapper {


    /// 新增菜品
    @Insert("insert into dish (name, category_id, price, image, description, create_time, update_time, create_user,update_user, status)" +
            "        values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{status})")
    @Options( useGeneratedKeys = true, keyProperty = "id")
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    // 分页查询
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    // 根据id修改菜品
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    // 根据分类id查询菜品数量
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    // 根据id查询菜品
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    // 根据分类id查询菜品
    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    DishVO list(Long categoryId);

    // 删除菜品
    @Delete("delete from dish where id = #{id}")
    void deleteByDishId(Long id);

    // 起售停售菜品
    @AutoFill(value = OperationType.UPDATE)
    @Update("update dish set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);
}
